//
//  KXWebViewController.swift
//  KXBook
//
//  Created by liujianlong on 2022/9/13.
//

import UIKit
import WebKit
class KXWebViewController: KXViewController {

    @IBOutlet var webview: WKWebView!
    override func viewDidLoad() {
        super.viewDidLoad()
        self.webview.navigationDelegate = self
        self.title = LS("隐私协议")
        let url = "https://baike.baidu.com".addingPercentEncoding(withAllowedCharacters: CharacterSet.urlQueryAllowed)
        let request = NSMutableURLRequest(url: URL(string: url!)!)
        request.httpMethod = "GET"
        self.webview.load(request as URLRequest)
        self.webview.scrollView.bouncesZoom = false
        Toast.startHud()
    }
}

extension KXWebViewController:WKNavigationDelegate{
    func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) {
        Toast.startHud()
    }
    func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
        Toast.stopHud()
    }
    func webView(_ webView: WKWebView, didFailProvisionalNavigation navigation: WKNavigation!, withError error: Error) {
        Toast.startHud(LS("加载失败"))
    }
    func webView(_ webView: WKWebView, didReceiveServerRedirectForProvisionalNavigation navigation: WKNavigation!) {
        Toast.startHud()
    }
}
